// fetch data from the server
const getList = () => {
  return new Promise((resolve, reject) => {
    var ajax = new XMLHttpRequest();
    ajax.open("get", "http://localhost:8089/api/bigdata");
    ajax.send();
    ajax.onreadystatechange = function () {
      if (ajax.readyState == 4 && ajax.status == 200) {
        const res = JSON.parse(ajax.responseText)
        if(res.resultCode === 1){
            resolve(res.resultInfo);
        }
      }
    };
  });
};

// get `container` element
const container = document.getElementById("container");

const renderList = async () => {
  const list = await getList();

  list.forEach((item) => {
    const div = document.createElement("div");
    div.className = "sunshine";
    div.innerHTML = `<img src="${item.src}" /><span>${item.text}</span>`;
    container.appendChild(div);
  });
};
renderList();
